﻿/*
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2009
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
*/

using System;
using MbUnit.Framework;
using WatiN.Core;
using DotNetNuke.Tests.UI.WatiN.Common;
using Gallio.Framework;
using DotNetNuke.Tests.UI.WatiN.Utilities;
using System.Configuration;
using WatiN.Core.DialogHandlers;
using DotNetNuke.Tests.UI.WatiN.Common.WatiNObjects;

namespace DotNetNuke.Tests.UI.WatiN.SiteTests
{
    [TestFixture]
    public class UserAccountsTests : STBase
    {
        #region Test Setup and TearDown

        [SetUp]
        public void SetUp()
        {
            SetUpTest();
        }

        [TearDown]
        public void TearDown()
        {
            TearDownTest();
        }

        #endregion

        #region Tests

        [Test]
        public void Add_User()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Act
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            System.Threading.Thread.Sleep(2000);
            UserPage userPage = new UserPage(homePage);
            userPage.AddNewUserStartLink.ClickNoWait();
            //Enter User inforrmation
            userPage.UserNameField.Value = TestUsers.User1.UserName;
            userPage.FirstNameField.Value = TestUsers.User1.FirstName;
            userPage.LastNameField.Value = TestUsers.User1.LastName;
            userPage.DisplayNameField.Value = TestUsers.User1.DisplayName;
            userPage.EmailField.Value = TestUsers.User1.EmailAddress;
            userPage.PasswordField.Value = TestUsers.User1.Password;
            userPage.ConfirmPasswordField.Value = TestUsers.User1.Password;
            userPage.AddNewUserLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);

            //Assert
            userPage.AllDisplayLink.Click();
            System.Threading.Thread.Sleep(1000);
            Assert.IsTrue(userPage.UserTable.InnerHtml.Contains(TestUsers.User1.UserName));
        }

        [Test]
        [DependsOn("Add_User")]
        public void Delete_User()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            //A user must first be added
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            System.Threading.Thread.Sleep(2000);
            UserPage userPage = new UserPage(homePage);
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(3000);
            userPage.AllDisplayLink.ClickNoWait();
            System.Threading.Thread.Sleep(1000);
            ConfirmDialogHandler dialog = new ConfirmDialogHandler();

            //Act 
            using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            {
                userPage.GetUserDeleteButton(TestUsers.User1.DisplayName).ClickNoWait();
                dialog.WaitUntilExists();
                dialog.OKButton.Click();
            }
            ieInstance.WaitForComplete();
            System.Threading.Thread.Sleep(5000);

            //Assert
            userPage.AllDisplayLink.Click();
            System.Threading.Thread.Sleep(1000);
            Assert.IsTrue(userPage.CheckUserDisplaysAsDeleted(TestUsers.User1.DisplayName));
            ieInstance.GoTo(SiteURL + "/home.aspx");
            System.Threading.Thread.Sleep(1500);
            //Log the Amin out 
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            //Attempt to login the deleted user
            LoginPage userLoginPage = new LoginPage(homePage);
            userLoginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);
            Assert.IsTrue(userLoginPage.LoginMessage.InnerHtml.Contains("Login Failed."));
        }

        [Test]
        public void Register_User()
        {
            //Arrange 
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            UserPage userPage = new UserPage(homePage);

            //Act
            loginPage.RegisterLink.Click();
            System.Threading.Thread.Sleep(2000);
            userPage.UserNameField.Value = TestUsers.Register.UserName;
            userPage.FirstNameField.Value = TestUsers.Register.FirstName;
            userPage.LastNameField.Value = TestUsers.Register.LastName;
            userPage.DisplayNameField.Value = TestUsers.Register.DisplayName;
            userPage.EmailField.Value = TestUsers.Register.EmailAddress;
            userPage.PasswordField.Value = TestUsers.Register.Password;
            userPage.ConfirmPasswordField.Value = TestUsers.Register.Password;
            userPage.RegisterButton.ClickNoWait();
            //No longer need to click proceed to login button
            //userPage.ProceedToLogin.Click();

            //Assert
            System.Threading.Thread.Sleep(2000);
            Assert.IsTrue(loginPage.RegisterLink.Text.StartsWith(TestUsers.Register.DisplayName));
        }

        [Test]
        public void UnAuthorize_User()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            UserPage userPage = new UserPage(homePage);

            //Add a User for Testing
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(2000);
            userPage.AllDisplayLink.Click();
            System.Threading.Thread.Sleep(1000);

            //Act
            userPage.GetUserEditButton(TestUsers.User1.DisplayName).Click(); ;
            userPage.UnauthorizeUserLink.ClickNoWait();

            //Assert
            Assert.IsTrue(userPage.PopUpMessageSpan.Text.Contains("User successfully Un-Authorized"));
            userPage.CancelLink.Click();
            userPage.UnauthorizedDisplayLink.ClickNoWait();
            System.Threading.Thread.Sleep(1500);
            Assert.IsTrue(userPage.GetUserRow(TestUsers.User1.DisplayName).InnerHtml.Contains(TestUsers.User1.UserName));
        }

        [Test]
        [DependsOn("UnAuthorize_User")]
        public void Authorize_User()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            UserPage userPage = new UserPage(homePage);

            //Add a User for Testing
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(2000);
            userPage.AllDisplayLink.Click();
            System.Threading.Thread.Sleep(1000);

            //Unauthorize the user
            userPage.GetUserEditButton(TestUsers.User1.DisplayName).Click();
            userPage.UnauthorizeUserLink.ClickNoWait();
            ieInstance.GoTo(SiteURL + "/Home.aspx");

            //Act
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            userPage.AllDisplayLink.Click();
            System.Threading.Thread.Sleep(1000);
            userPage.GetUserEditButton(TestUsers.User1.DisplayName).ClickNoWait();
            userPage.AuthorizeUserLink.ClickNoWait();

            //Assert
            Assert.IsTrue(userPage.PopUpMessageSpan.Text.Contains("User successfully Authorized"));
            userPage.CancelLink.Click();
            userPage.UnauthorizedDisplayLink.Click();
            Assert.IsFalse(userPage.UserTable.InnerHtml.Contains(TestUsers.User1.DisplayName));
        }

        [Test]
        public void Update_Password()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            UserPage userPage = new UserPage(homePage);

            //Add User for Testing
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(2000);
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);

            //Act 
            loginPage.RegisterLink.Click();
            UserProfilePage profilePage = new UserProfilePage(homePage);
            profilePage.EditProfileLink.ClickNoWait();
            profilePage.ManagePasswordLink.ClickNoWait();
            profilePage.CurrentPasswordField.Value = TestUsers.User1.Password;
            profilePage.NewPasswordField.Value = TestUsers.User1.NewPassword;
            profilePage.ConfirmNewPasswordField.Value = TestUsers.User1.NewPassword;
            profilePage.ChangePasswordLink.ClickNoWait();

            //Assert 
            Assert.IsTrue(userPage.ModuleMessageSpan.Text.Contains("The password has been reset."));
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);
            Assert.IsTrue(loginPage.LoginMessage.InnerHtml.Contains("Login Failed."));
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.NewPassword);
            Assert.IsTrue(homePage.RegisterLink.Text.Contains(TestUsers.User1.DisplayName));
        }

        [Test]
        public void Force_Password_Change()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            System.Threading.Thread.Sleep(1500);
            UserPage userPage = new UserPage(homePage);

            //Add User for Testing
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(2000);
            userPage.AllDisplayLink.Click();
            System.Threading.Thread.Sleep(1000);

            //Act 
            userPage.GetUserEditButton(TestUsers.User1.DisplayName).Click();
            userPage.ForcePasswordChangeLink.ClickNoWait();
            Assert.IsTrue(userPage.PopUpMessageSpan.InnerHtml.Contains("User must update password on next login"));

            //Assert 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginLink.Click();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);

            Assert.IsTrue(userPage.PopUpMessageSpan.InnerHtml.Contains("Please update your password before continuing"));
            UserProfilePage profilePage = new UserProfilePage(homePage);
            profilePage.CurrentPasswordField.Value = TestUsers.User1.Password;
            profilePage.NewPasswordField.Value = TestUsers.User1.NewPassword;
            profilePage.ConfirmNewPasswordField.Value = TestUsers.User1.NewPassword;
            profilePage.ChangePasswordLink.ClickNoWait();
            System.Threading.Thread.Sleep(1500);
            Assert.IsTrue(homePage.RegisterLink.InnerHtml.Contains(TestUsers.User1.DisplayName));
          
        }

        [Test]
        public void Update_Profile_As_Admin()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            UserPage userPage = new UserPage(homePage);

            //Add User for Testing
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(2000);
            userPage.AllDisplayLink.Click();
            System.Threading.Thread.Sleep(1000);

            //Act 
            userPage.GetUserEditButton(TestUsers.User1.DisplayName).Click();
            UserProfilePage profilePage = new UserProfilePage(homePage);
            profilePage.ManageProfileLink.ClickNoWait();
            profilePage.UserStreetField.Value = "Test Street";
            profilePage.ProfileUpdateLink.ClickNoWait();

            //Assert
            System.Threading.Thread.Sleep(1000);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            userPage.AllDisplayLink.ClickNoWait();
            System.Threading.Thread.Sleep(1500);
            TableCell userAddress = userPage.GetUserRow(TestUsers.User1.DisplayName).TableCells[8];
            Assert.IsTrue(userAddress.Text.Contains("Test Street"));
        }

        [Test]
        public void Update_Profile_As_User()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            UserPage userPage = new UserPage(homePage);

            //Add User for Testing
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(2000);
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);

            //Act 
            loginPage.RegisterLink.ClickNoWait();
            UserProfilePage profilePage = new UserProfilePage(homePage);
            profilePage.EditProfileLink.ClickNoWait();
            profilePage.UserStreetField.Value = "Test Street";
            profilePage.ProfileUpdateLink.ClickNoWait();

            //Assert 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.RegisterLink.ClickNoWait();
            profilePage.EditProfileLink.ClickNoWait();
            Assert.IsTrue(profilePage.UserStreetField.Text.Contains("Test Street"));
        }

        [Test]
        public void Add_New_Visible_Profile_Feild()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            UserPage userPage = new UserPage(homePage);


            //Add a User for Testing
            System.Threading.Thread.Sleep(1500);
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(2000);

            userPage.ManageProfilePropertiesLink.Click();
            ProfilePropertiesPage propertiesPage = new ProfilePropertiesPage(homePage);

            //Act
            //Add Text Property
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "TextProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("349");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.LengthTextField.Value = "10";
            propertiesPage.VisibleCheckBox.Checked = true;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing
            TableRow textPropertyRow = propertiesPage.GetPropertyRow("TextProperty");
            Assert.IsTrue(textPropertyRow.Exists);
            Assert.IsTrue(textPropertyRow.Equals(propertiesPage.PropertyTable.TableRows[1]));

            //Add DateTime Property
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "DateTimeProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("360");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.VisibleCheckBox.Checked = true;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing
            TableRow dateTimePropertyRow = propertiesPage.GetPropertyRow("DateTimeProperty");
            Assert.IsTrue(dateTimePropertyRow.Exists);
            Assert.IsTrue(dateTimePropertyRow.Equals(propertiesPage.PropertyTable.TableRows[2]));

            //Add Country Field
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "CountryProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("356");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.VisibleCheckBox.Checked = true;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing 
            TableRow countryPropertyRow = propertiesPage.GetPropertyRow("CountryProperty");
            Assert.IsTrue(countryPropertyRow.Exists);
            Assert.IsTrue(countryPropertyRow.Equals(propertiesPage.PropertyTable.TableRows[3]));

            //Add Region Field
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "RegionProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("357");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.VisibleCheckBox.Checked = true;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing 
            TableRow regionPropertyRow = propertiesPage.GetPropertyRow("RegionProperty");
            Assert.IsTrue(regionPropertyRow.Exists);
            Assert.IsTrue(regionPropertyRow.Equals(propertiesPage.PropertyTable.TableRows[4]));

            //Add Image Field
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "ImageProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("361");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.VisibleCheckBox.Checked = true;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing 
            TableRow imagePropertyRow = propertiesPage.GetPropertyRow("ImageProperty");
            Assert.IsTrue(imagePropertyRow.Exists);
            Assert.IsTrue(imagePropertyRow.Equals(propertiesPage.PropertyTable.TableRows[5]));

            //Assert
            //Check that the properties show up in the users profile correctly
            ieInstance.GoTo(SiteURL + "/home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);
            homePage.RegisterLink.ClickNoWait();
            UserProfilePage profilePage = new UserProfilePage(homePage);
            profilePage.EditProfileLink.ClickNoWait();
            profilePage.ManageProfileLink.Click();
            //Enter Values for all the new properties
            profilePage.TextPropertyField.Value = "12345678910";
            profilePage.DateTimeDateField.Value = "04/05/2010";
            profilePage.HourSelectList.Select("08");
            profilePage.MinuteSelectList.Select("30");
            profilePage.AmPmSelectList.Select("PM");
            profilePage.CountryPropertySelectList.SelectByValue("Belgium");
            System.Threading.Thread.Sleep(2000);
            profilePage.RegionPropertyField.Value = "Test Region";
            profilePage.ImagePropertyUploadFileLink.Click();
            profilePage.ImagePropertyFileUpload.Set(ImagePath);
            profilePage.ImagePropertySaveFileLink.Click();
            profilePage.ProfileUpdateLink.Click();
            System.Threading.Thread.Sleep(2000);

            //Assert that they were save correctly.
            //Too many Characters were entered, the string should be shortened to "1234567891"
            Assert.IsTrue(profilePage.TextPropertyField.Text.CompareTo("1234567891") == 0);
            Assert.IsTrue(profilePage.DateTimeDateField.Text.CompareTo("4/5/2010") == 0);
            Assert.IsTrue(profilePage.HourSelectList.SelectedItem.CompareTo("08") == 0);
            Assert.IsTrue(profilePage.MinuteSelectList.SelectedItem.CompareTo("30") == 0);
            Assert.IsTrue(profilePage.AmPmSelectList.SelectedItem.CompareTo("PM") == 0);
            Assert.IsTrue(profilePage.CountryPropertySelectList.SelectedItem.Contains("Belgium"), profilePage.CountryPropertySelectList.SelectedItem);
            Assert.IsTrue(profilePage.RegionPropertyField.Text.CompareTo("Test Region") == 0);
            Assert.IsTrue(profilePage.FileSelectList.SelectedItem.CompareTo(ImageName) == 0);

        }

        [Test]
        public void Add_New_Invisible_Profile_Field()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            UserPage userPage = new UserPage(homePage);


            //Add a User for Testing
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(2000);
            userPage.ManageProfilePropertiesLink.Click();
            ProfilePropertiesPage propertiesPage = new ProfilePropertiesPage(homePage);

            //Act
            //Add Text Property
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "TextProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("349");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.LengthTextField.Value = "10";
            propertiesPage.VisibleCheckBox.Checked = false;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing
            TableRow textPropertyRow = propertiesPage.GetPropertyRow("TextProperty");
            Assert.IsTrue(textPropertyRow.Exists);
            Assert.IsTrue(textPropertyRow.Equals(propertiesPage.PropertyTable.TableRows[1]));
            
            //Add DateTime Property
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "DateTimeProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("360");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.VisibleCheckBox.Checked = false;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing
            TableRow dateTimePropertyRow = propertiesPage.GetPropertyRow("DateTimeProperty");
            Assert.IsTrue(dateTimePropertyRow.Exists);
            Assert.IsTrue(dateTimePropertyRow.Equals(propertiesPage.PropertyTable.TableRows[2]));
            
            //Add Country Field
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "CountryProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("356");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.VisibleCheckBox.Checked = false;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing 
            TableRow countryPropertyRow = propertiesPage.GetPropertyRow("CountryProperty");
            Assert.IsTrue(countryPropertyRow.Exists);
            Assert.IsTrue(countryPropertyRow.Equals(propertiesPage.PropertyTable.TableRows[3]));
        
            //Add Region Field
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "RegionProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("357");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.LengthTextField.Value = "10";
            propertiesPage.VisibleCheckBox.Checked = false;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing 
            TableRow regionPropertyRow = propertiesPage.GetPropertyRow("RegionProperty");
            Assert.IsTrue(regionPropertyRow.Exists);
            Assert.IsTrue(regionPropertyRow.Equals(propertiesPage.PropertyTable.TableRows[4]));
         
            //Add Image Field
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "ImageProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("361");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.VisibleCheckBox.Checked = false;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing 
            TableRow imagePropertyRow = propertiesPage.GetPropertyRow("ImageProperty");
            Assert.IsTrue(imagePropertyRow.Exists);
            Assert.IsTrue(imagePropertyRow.Equals(propertiesPage.PropertyTable.TableRows[5]));

            //Navigate to the User Accounts Page to assert that the properties are visible to the host
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            userPage.AllDisplayLink.Click();
            System.Threading.Thread.Sleep(1000);
            userPage.GetUserEditButton(TestUsers.User1.DisplayName).Click();
            UserProfilePage profilePage = new UserProfilePage(homePage);

            profilePage.ManageProfileLink.ClickNoWait();
            System.Threading.Thread.Sleep(2500);
            //Assert
            Assert.IsTrue(profilePage.TextPropertyField.Exists);
            Assert.IsTrue(profilePage.DateTimeDateField.Exists);
            Assert.IsTrue(profilePage.HourSelectList.Exists);
            Assert.IsTrue(profilePage.MinuteSelectList.Exists);
            Assert.IsTrue(profilePage.AmPmSelectList.Exists);
            Assert.IsTrue(profilePage.CountryPropertySelectList.Exists);
            Assert.IsTrue(profilePage.RegionPropertyField.Exists);
            Assert.IsTrue(profilePage.ImageFileSelectList.Exists);

            //Navigate to the users Profile Page 
            ieInstance.GoTo(SiteURL + "/home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);
            homePage.RegisterLink.ClickNoWait();
            profilePage.EditProfileLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);
            //Assert
            Assert.IsFalse(profilePage.TextPropertyField.Exists);
            Assert.IsFalse(profilePage.DateTimeDateField.Exists);
            Assert.IsFalse(profilePage.HourSelectList.Exists);
            Assert.IsFalse(profilePage.MinuteSelectList.Exists);
            Assert.IsFalse(profilePage.AmPmSelectList.Exists);
            Assert.IsFalse(profilePage.CountryPropertySelectList.Exists);
            Assert.IsFalse(profilePage.RegionPropertyField.Exists);
            Assert.IsFalse(profilePage.ImageFolderSelectList.Exists);
            Assert.IsFalse(profilePage.FileUpload.Exists);
        }

        [Test]
        public void Add_New_Required_Profile_Field_Valid_Profile_Required()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            System.Threading.Thread.Sleep(1500);
            UserPage userPage = new UserPage(homePage);

            //Make Valid Profiles required 
            userPage.UserSettingsLink.Click();
            UserSettingsPage userSettingsPage = new UserSettingsPage(homePage);
            userSettingsPage.ValidProfileRequiredForLoginRadioButton.Checked = true;
            userSettingsPage.UpdateLink.Click();
            System.Threading.Thread.Sleep(1500);

            //Add a User for Testing
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(2000);
            userPage.ManageProfilePropertiesLink.Click();
            ProfilePropertiesPage propertiesPage = new ProfilePropertiesPage(homePage);

            //Act
            //Add Text Property
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "TextProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("349");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.LengthTextField.Value = "10";
            propertiesPage.VisibleCheckBox.Checked = true;
            propertiesPage.RequiredCheckBox.Checked = true;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing
            TableRow textPropertyRow = propertiesPage.GetPropertyRow("TextProperty");
            Assert.IsTrue(textPropertyRow.Exists);
            Assert.IsTrue(textPropertyRow.Equals(propertiesPage.PropertyTable.TableRows[1]));

            //Add DateTime Property
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "DateTimeProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("360");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.VisibleCheckBox.Checked = true;
            propertiesPage.RequiredCheckBox.Checked = true;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing
            TableRow dateTimePropertyRow = propertiesPage.GetPropertyRow("DateTimeProperty");
            Assert.IsTrue(dateTimePropertyRow.Exists);
            Assert.IsTrue(dateTimePropertyRow.Equals(propertiesPage.PropertyTable.TableRows[2]));

            //Add Country Field
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "CountryProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("356");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.VisibleCheckBox.Checked = true;
            propertiesPage.RequiredCheckBox.Checked = true;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing 
            TableRow countryPropertyRow = propertiesPage.GetPropertyRow("CountryProperty");
            Assert.IsTrue(countryPropertyRow.Exists);
            Assert.IsTrue(countryPropertyRow.Equals(propertiesPage.PropertyTable.TableRows[3]));

            //Add Region Field
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "RegionProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("357");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.LengthTextField.Value = "10";
            propertiesPage.VisibleCheckBox.Checked = true;
            propertiesPage.RequiredCheckBox.Checked = true;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing 
            TableRow regionPropertyRow = propertiesPage.GetPropertyRow("RegionProperty");
            Assert.IsTrue(regionPropertyRow.Exists);
            Assert.IsTrue(regionPropertyRow.Equals(propertiesPage.PropertyTable.TableRows[4]));

            //Add Image Field
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "ImageProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("361");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.VisibleCheckBox.Checked = true;
            propertiesPage.RequiredCheckBox.Checked = true;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing 
            TableRow imagePropertyRow = propertiesPage.GetPropertyRow("ImageProperty");
            Assert.IsTrue(imagePropertyRow.Exists);
            Assert.IsTrue(imagePropertyRow.Equals(propertiesPage.PropertyTable.TableRows[5]));

            //Assert 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);
            Assert.IsTrue(homePage.PopUpMessageSpan.InnerHtml.Contains("Please update your profile before continuing"));

            UserProfilePage profilePage = new UserProfilePage(homePage);
            Assert.IsTrue(profilePage.RequiredElements.Count == 5, profilePage.RequiredElements.Count.ToString());
            //Enter Values for all the new properties
            profilePage.TextPropertyField.Value = "12345678910";
            profilePage.DateTimeDateField.Value = "04/05/2010";
            profilePage.HourSelectList.Select("08");
            profilePage.MinuteSelectList.Select("30");
            profilePage.AmPmSelectList.Select("PM");
            profilePage.CountryPropertySelectList.Select("Belgium");
            System.Threading.Thread.Sleep(2000);
            profilePage.RegionPropertyField.Value = "Test Region";
            profilePage.ImagePropertyUploadFileLink.Click();
            profilePage.ImagePropertyFileUpload.Set(ImagePath);
            profilePage.ImagePropertySaveFileLink.Click();
            profilePage.ProfileUpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);
            Assert.IsTrue(homePage.RegisterLink.InnerHtml.Contains(TestUsers.User1.DisplayName));
        }

        [Test]
        public void Add_New_Required_Profile_Field_Valid_Profile_Not_Required()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            System.Threading.Thread.Sleep(1500);
            UserPage userPage = new UserPage(homePage);

            //Make Valid Profiles required 
            userPage.UserSettingsLink.Click();
            UserSettingsPage userSettingsPage = new UserSettingsPage(homePage);
            userSettingsPage.ValidProfileNotRequiredForLoginRadioButton.Checked = true;
            userSettingsPage.UpdateLink.Click();
            System.Threading.Thread.Sleep(1500);

            //Add a User for Testing
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(2000);
            userPage.ManageProfilePropertiesLink.Click();
            ProfilePropertiesPage propertiesPage = new ProfilePropertiesPage(homePage);

            //Act
            //Add Text Property
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "TextProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("349");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.LengthTextField.Value = "10";
            propertiesPage.VisibleCheckBox.Checked = true;
            propertiesPage.RequiredCheckBox.Checked = true;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing
            TableRow textPropertyRow = propertiesPage.GetPropertyRow("TextProperty");
            Assert.IsTrue(textPropertyRow.Exists);
            Assert.IsTrue(textPropertyRow.Equals(propertiesPage.PropertyTable.TableRows[1]));

            //Add DateTime Property
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "DateTimeProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("360");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.VisibleCheckBox.Checked = true;
            propertiesPage.RequiredCheckBox.Checked = true;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing
            TableRow dateTimePropertyRow = propertiesPage.GetPropertyRow("DateTimeProperty");
            Assert.IsTrue(dateTimePropertyRow.Exists);
            Assert.IsTrue(dateTimePropertyRow.Equals(propertiesPage.PropertyTable.TableRows[2]));

            //Add Country Field
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "CountryProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("356");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.VisibleCheckBox.Checked = true;
            propertiesPage.RequiredCheckBox.Checked = true;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing 
            TableRow countryPropertyRow = propertiesPage.GetPropertyRow("CountryProperty");
            Assert.IsTrue(countryPropertyRow.Exists);
            Assert.IsTrue(countryPropertyRow.Equals(propertiesPage.PropertyTable.TableRows[3]));

            //Add Region Field
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "RegionProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("357");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.LengthTextField.Value = "10";
            propertiesPage.VisibleCheckBox.Checked = true;
            propertiesPage.RequiredCheckBox.Checked = true;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing 
            TableRow regionPropertyRow = propertiesPage.GetPropertyRow("RegionProperty");
            Assert.IsTrue(regionPropertyRow.Exists);
            Assert.IsTrue(regionPropertyRow.Equals(propertiesPage.PropertyTable.TableRows[4]));

            //Add Image Field
            propertiesPage.AddNewProfilePropertyLink.Click();
            propertiesPage.PropertyNameField.Value = "ImageProperty";
            propertiesPage.DataTypeSelectList.SelectByValue("361");
            propertiesPage.PropertyCategoryField.Value = "Test Fields";
            propertiesPage.VisibleCheckBox.Checked = true;
            propertiesPage.RequiredCheckBox.Checked = true;
            propertiesPage.NextButton.Click();
            propertiesPage.ReturnToProfilePropertiesLink.Click();
            //Check the property was added to the list before continuing 
            TableRow imagePropertyRow = propertiesPage.GetPropertyRow("ImageProperty");
            Assert.IsTrue(imagePropertyRow.Exists);
            Assert.IsTrue(imagePropertyRow.Equals(propertiesPage.PropertyTable.TableRows[5]));

            //Assert 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);
            Assert.IsTrue(homePage.RegisterLink.InnerHtml.Contains(TestUsers.User1.DisplayName));
            homePage.RegisterLink.ClickNoWait();
            UserProfilePage profilePage = new UserProfilePage(homePage);
            profilePage.EditProfileLink.ClickNoWait();
            profilePage.ManageProfileLink.ClickNoWait();
            System.Threading.Thread.Sleep(2500);
            Assert.IsTrue(profilePage.RequiredElements.Count == 12, profilePage.RequiredElements.Count.ToString());
            //Try and update the users profile
            profilePage.TimeZoneSelectList.Select("(UTC -10:00) Hawaii");
            profilePage.ProfileUpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);
            Assert.IsTrue(profilePage.RequiredPropertiesSpans.Count == 5);
            //Enter Values for all the new properties
            profilePage.TextPropertyField.Value = "12345678910";
            profilePage.DateTimeDateField.Value = "04/05/2010";
            profilePage.HourSelectList.Select("08");
            profilePage.MinuteSelectList.Select("30");
            profilePage.AmPmSelectList.Select("PM");
            profilePage.CountryPropertySelectList.Select("Belgium");
            System.Threading.Thread.Sleep(2000);
            profilePage.RegionPropertyField.Value = "Test Region";
            System.Threading.Thread.Sleep(1000);
            profilePage.ImagePropertyUploadFileLink.ClickNoWait();
            profilePage.ImagePropertyFileUpload.Set(ImagePath);
            System.Threading.Thread.Sleep(1500);
            profilePage.ImagePropertySaveFileLink.ClickNoWait();
            System.Threading.Thread.Sleep(1500);
            profilePage.ProfileUpdateLink.Click();
            System.Threading.Thread.Sleep(2000);
            //Assert that they were saved correctly.
            //Too many Characters were entered, the string should be shortened to "1234567891"
            Assert.IsTrue(profilePage.TextPropertyField.Text.CompareTo("1234567891") == 0);
            Assert.IsTrue(profilePage.DateTimeDateField.Text.CompareTo("4/5/2010") == 0);
            Assert.IsTrue(profilePage.HourSelectList.SelectedItem.CompareTo("08") == 0);
            Assert.IsTrue(profilePage.MinuteSelectList.SelectedItem.CompareTo("30") == 0);
            Assert.IsTrue(profilePage.AmPmSelectList.SelectedItem.CompareTo("PM") == 0);
            Assert.IsTrue(profilePage.CountryPropertySelectList.SelectedItem.CompareTo("Belgium") == 0);
            Assert.IsTrue(profilePage.RegionPropertyField.Text.CompareTo("Test Region") == 0);
            Assert.IsTrue(profilePage.FileSelectList.SelectedItem.CompareTo(ImageName) == 0);
        }

        [Test]
        public void Redirect_on_Login()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
           
            //Add a User for testing
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            System.Threading.Thread.Sleep(1500);
            UserPage userPage = new UserPage(homePage);
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(1500);
            //Add A Page for testing
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(3000);
            String pageName = "Test Page";
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                newPage.PageTemplateSelect.Select("None Specified");
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
                newPage.PageTemplateSelect.Select("None Specified");
            }

            newPage.PageNameField.Value = pageName;
            newPage.AllUsersViewPermissionCheckbox.ClickNoWait();
            newPage.AddPageLink.ClickNoWait();
            System.Threading.Thread.Sleep(4000);

            //Act 
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            userPage.UserSettingsLink.Click();
            UserSettingsPage userSettings = new UserSettingsPage(homePage);
            userSettings.RedirectAfterLoginSelectList.Select(pageName);
            userSettings.UpdateLink.Click();
            System.Threading.Thread.Sleep(1000);
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);

            //Assert 
            SiteMenu menu = new SiteMenu(homePage);
            Assert.IsTrue(menu.BreadCrumbSpan.InnerHtml.Contains(pageName));
        }

        [Test]
        public void Redirect_on_Registration()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;

            //Add A Page for testing
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(3000);
            String pageName = "Test Page";
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                newPage.PageTemplateSelect.Select("None Specified");
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
                newPage.PageTemplateSelect.Select("None Specified");
            }

            newPage.PageNameField.Value = pageName;
            newPage.AllUsersViewPermissionCheckbox.Click();
            newPage.AddPageLink.ClickNoWait();
            System.Threading.Thread.Sleep(4000);

            //Act 
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            UserPage userPage = new UserPage(homePage);
            userPage.UserSettingsLink.Click();
            UserSettingsPage userSettings = new UserSettingsPage(homePage);
            userSettings.RedirectAfterRegistrationSelectList.Select(pageName);
            userSettings.UpdateLink.Click();
            System.Threading.Thread.Sleep(1000);
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            userPage.RegisterUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(2000);

            //Assert 
            SiteMenu menu = new SiteMenu(homePage);
            Assert.IsTrue(menu.BreadCrumbSpan.InnerHtml.Contains(pageName));
        }

        [Test]
        public void Add_Duplicate_User_Fail()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            UserPage userPage = new UserPage(homePage);

            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(1000);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");

            //Act
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, "Different Name");
            System.Threading.Thread.Sleep(1000);

            //Assert
            Assert.IsTrue(userPage.PopUpMessageSpan.InnerHtml.Contains("A User Already Exists For the Username Specified."));
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            userPage.AllDisplayLink.Click();
            System.Threading.Thread.Sleep(1000);
            Assert.IsFalse(userPage.UserTable.InnerHtml.Contains("Different Name"));
            Assert.IsTrue(userPage.UserTable.InnerHtml.Contains(TestUsers.User1.DisplayName));
        }


        #endregion 
    }
}

